import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { ConfigProvider } from '../../providers/config/config';
import { HttpServicesProvider } from '../../providers/http-services/http-services';

/**
 * Generated class for the CategoryPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-category',
  templateUrl: 'category.html',
})
export class CategoryPage {
  public recList = []
  public cateList = []

  public leftCate = []//左侧分类数据
  public rightCate = []//右侧分类数据

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public config: ConfigProvider,
    public httpServices: HttpServicesProvider
  ) {
    // 左侧分类数据
    this.getLeftData()
  }


  // 左侧分类的数据
  getLeftData() {
    this.httpServices.requestData('api/pcate', data => {
      this.leftCate = data.result;
      // 调用右侧分类
      this.getRightData(data.result[0]._id)
    })
  }

  // 左侧分类的数据
  getRightData(pid) {
    this.httpServices.requestData('api/pcate?pid=' + pid, data => {
      this.rightCate = data.result;
    })
  }

  // 跳转商品列表页面
  pushProductPage(value){
    this.navCtrl.push('ProductListPage',{'cid':value})
  }
}
